<!DOCTYPE html>  
<html>
<meta charset="utf-8" />  
<title>WebSocket Test</title>  
<script language="javascript"type="text/javascript">  
    var ws = new WebSocket('ws://localhost:3000/ws');//客户端链接服务器
 
	// ws.onopen = function(evt) { 
		

	// };
	ws.addEventListener('open',function(evt){
		console.log("Connection open ..."); 
		ws.send("Hello WebSockets!");
	})
	
	ws.onmessage = function(evt) {
		console.log( "Received Message: " + evt.data);
		ws.close();
	};
	
	ws.addEventListener("close", function(event) {
		var code = event.code;
		var reason = event.reason;
		var wasClean = event.wasClean;
		console.log('event',event)
		// handle close event
	});

</script>  
<body>
<h2>WebSocket Test</h2>  
<div id="output"></div>  
</body>
</html>